#include "AquariumApp.h"
#include "global.h"
AquariumApp::AquariumApp(void)
{
		
}


AquariumApp::~AquariumApp(void)
{
	
}

void AquariumApp::Init()
{
	InitOgreApp::InitApp();
	g_SceneManager = m_SceneManager;
	InitKeyboard();
	//this->FullScreen();
}

void AquariumApp::SetLight()
{

}

void AquariumApp::Render()
{
	InitOgreApp::Render();
}

bool AquariumApp::frameRenderingQueued( const Ogre::FrameEvent &_evt )
{
	if ( m_Window->isClosed() ) return false;

	UpdateKeyboard();
	return true;
}

void AquariumApp::InitKeyboard()
{
	DWORD window_handle = NULL;
	std::ostringstream windowHndStr;
	m_Window->getCustomAttribute( "WINDOW", &window_handle );
	windowHndStr << window_handle;

	OIS::ParamList param_list;
	param_list.insert( make_pair( std::string( "WINDOW" ), windowHndStr.str() ) );
	
	m_InputManager = OIS::InputManager::createInputSystem( param_list );
	m_Keyboard  = (OIS::Keyboard *)m_InputManager->createInputObject( OIS::OISKeyboard, false );
}

void AquariumApp::UpdateKeyboard()
{
	m_Keyboard->capture();
	if(m_Keyboard->isKeyDown(OIS::KC_ESCAPE))
	{
		exit(0);
	}
}

void AquariumApp::windowClosed( Ogre::RenderWindow* rw )
{
	if( rw == m_Window )
	{
		if( m_InputManager )
		{
			m_InputManager->destroyInputObject( m_Keyboard );
			OIS::InputManager::destroyInputSystem( m_InputManager );
			m_InputManager = NULL;
		}
	}
}

